<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="common/header :: common(~{::title},~{::link})">
    <meta charset="UTF-8">
    <title>首页</title>
    <link rel="stylesheet" th:href="@{../static/css/font.css}">
</head>
<body ng-app="user" ng-controller="userController">
<!--导航条-->
<div>
    <ng-include src="'../static/nav.html'"></ng-include>
</div>
<h1>欢迎页</h1>
<input ng-model="user.username">
<input ng-model="user.pwd">
<button ng-click="loginUsers()">登录</button>
<button ng-click="register()">register</button>
</body>
<script>
    var user = angular.module("user", ["ngResource"]);
    user.service("userServices", function ($resource) {
        //创建资源对象
        //let userServices = $resource('/user/:id', {id: '@id'});
        this.registers= function (entity) {
            return $resource('/user/register').save(entity);
        }
        this.login= function (entity) {
            return $resource('/user/login').save(entity);
        }
    });
    user.controller("userController", function ($scope, userServices) {
        $scope.register = function () {
            userServices.registers($scope.user).$promise.then(function success(response) {
                console.log(response);
            })
        }
        $scope.loginUsers = function () {
            userServices.login($scope.user).$promise.then(function success(response) {
                console.log(response);
            })
        }
    });
</script>
</html>